package cn.miju.ser.framework.handler;

import java.util.Objects;

/**
 * <pre>
 * 上下文操作类
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-04-20 10:34
 */
public class MiJuContextHandler {
    private static final ThreadLocal<MiJuContext> MIJU_CONTEXT_THREAD_LOCAL = new MiJuThreadLocal();

    static class MiJuThreadLocal extends ThreadLocal<MiJuContext> {
        @Override
        public MiJuContext get() {
            MiJuContext miJuContext = super.get();
            return Objects.isNull(miJuContext) ? new MiJuContext() : miJuContext;
        }
    }

    public static void setMiJuContext(MiJuContext miJuContext) {
        MIJU_CONTEXT_THREAD_LOCAL.set(miJuContext);
    }

    public static MiJuContext getMiJuContext() {
        return MIJU_CONTEXT_THREAD_LOCAL.get();
    }

    public static void removeMiJuContext() {
        MIJU_CONTEXT_THREAD_LOCAL.remove();
    }
}
